#include <typescommon.h>
// switch
uint32_t getFunc0()
{
    return 0X53;
}
uint32_t getFunc1()
{
    return 0X12;
}
uint32_t getFunc2()
{
    return 0XB1;
}
uint32_t getFunc3()
{
    return 0X29;
}
uint32_t getFunc4()
{
    return 0X67;
}
uint32_t getFunc5()
{
    return 0X9C;
}
uint32_t getFunc6()
{
    return 0XE1;
}
uint32_t getFunc7()
{
    return 0XAB;
}
uint32_t getFunc8()
{
    return 0X3F;
}
uint32_t getFunc9()
{
    return 0XE5;
}
uint32_t getFunc10()
{
    return 0X63;
}
uint32_t getFunc11()
{
    return 0X90;
}
uint32_t getFunc12()
{
    return 0XD1;
}
uint32_t getFunc13()
{
    return 0X58;
}
uint32_t getFunc14()
{
    return 0XDA;
}
uint32_t getFunc15()
{
    return 0X74;
}
uint32_t getFunc16()
{
    return 0X26;
}
uint32_t getFunc17()
{
    return 0XB3;
}
uint32_t getFunc18()
{
    return 0XCE;
}
uint32_t getFunc19()
{
    return 0XF7;
}
uint32_t getSwitchVal(int getid)
{
#undef getSwitchDef
#define getSwitchDef(id)        \
    case id:                    \
    {                           \
        tmpval = getFunc##id(); \
        break;                  \
    }
    uint32_t tmpval;
    switch (getid)
    {
        getSwitchDef(0)
        getSwitchDef(1)
        getSwitchDef(2)
        getSwitchDef(3)
        getSwitchDef(4)
        getSwitchDef(5)
        getSwitchDef(6)
        getSwitchDef(7)
        getSwitchDef(8)
        getSwitchDef(9)
        getSwitchDef(10)
        getSwitchDef(11)
        getSwitchDef(12)
        getSwitchDef(13)
        getSwitchDef(14)
        getSwitchDef(15)
        getSwitchDef(16)
        getSwitchDef(17)
        getSwitchDef(18)
        getSwitchDef(19)
    default:
    {
        logerror("");
        tmpval = getFunc0();
        break;
    }
    }
    return tmpval;
}

uint32_t getIfVal(int getid)
{
#undef getIfValDef
#define getIfValDef(id)         \
    else if (getid == id)       \
    {                           \
        tmpval = getFunc##id(); \
    }
    uint32_t tmpval;
    if (getid == 0)
    {
        tmpval = getFunc0();
    }
    getIfValDef(1)
    getIfValDef(2)
    getIfValDef(3)
    getIfValDef(4)
    getIfValDef(5)
    getIfValDef(6)
    getIfValDef(7)
    getIfValDef(8)
    getIfValDef(9)
    getIfValDef(10)
    getIfValDef(11)
    getIfValDef(12)
    getIfValDef(13)
    getIfValDef(14)
    getIfValDef(15)
    getIfValDef(16)
    getIfValDef(17)
    getIfValDef(18)
    getIfValDef(19)
    else
    {
        logerror("");
        tmpval = getFunc0();
    }
    return tmpval;
}

typedef uint32_t (*funcptr)();
static funcptr funclist[] ={
    getFunc0,
    getFunc1,
    getFunc2,
    getFunc3,
    getFunc4,
    getFunc5,
    getFunc6,
    getFunc7,
    getFunc8,
    getFunc9,
    getFunc10,
    getFunc11,
    getFunc12,
    getFunc13,
    getFunc14,
    getFunc15,
    getFunc16,
    getFunc17,
    getFunc18,
    getFunc19,
};
uint32_t getmapVal(uint32_t getid)
{
    if (getid < (sizeof(funclist) / sizeof(funclist[0])))
    {
        return funclist[getid]();
    }
    else
    {
        logerror("");
        return funclist[0]();
    }
}

#define GET_VAL_ID_MY_USE 19
uint32_t doSwitchIfSpeed(int useIf, int funcid)
{
    uint32_t tmpSum = 0;
    for (int i = 0; i < 20000000; i++)
    {
        switch (useIf)
        {
        case 0:
        {
            tmpSum += getSwitchVal(funcid);
            break;
        }
        case 1:
        {
            tmpSum += getIfVal(funcid);
            break;
        }
        case 2:
        {
            tmpSum += getmapVal(funcid);
            break;
        }
        default:
        {
            logdebug("error");
            break;
        }
        }
    }
    return tmpSum;
}

int main(int argc, char **argv)
{
    sysTmrType tmptmr;
    int useFuncId = 0;
    {
        useFuncId = 0;
        logdebug("use func id:%d", useFuncId);
        sysTmrMsBegin(tmptmr);
        doSwitchIfSpeed(0, useFuncId);
        logdebug("switch sum,time:%lu", sysTmrMsRunMs(tmptmr));

        sysTmrMsBegin(tmptmr);
        doSwitchIfSpeed(1, useFuncId);
        logdebug("if sum,time:%lu", sysTmrMsRunMs(tmptmr));

        sysTmrMsBegin(tmptmr);
        doSwitchIfSpeed(2, useFuncId);
        logdebug("map sum,time:%lu", sysTmrMsRunMs(tmptmr));
    }
    {
        useFuncId = 10;
        logdebug("use func id:%d", useFuncId);
        sysTmrMsBegin(tmptmr);
        doSwitchIfSpeed(0, useFuncId);
        logdebug("switch sum,time:%lu", sysTmrMsRunMs(tmptmr));

        sysTmrMsBegin(tmptmr);
        doSwitchIfSpeed(1, useFuncId);
        logdebug("if sum,time:%lu", sysTmrMsRunMs(tmptmr));

        sysTmrMsBegin(tmptmr);
        doSwitchIfSpeed(2, useFuncId);
        logdebug("map sum,time:%lu", sysTmrMsRunMs(tmptmr));
    }
    {
        useFuncId = 19;
        logdebug("use func id:%d", useFuncId);
        sysTmrMsBegin(tmptmr);
        doSwitchIfSpeed(0, useFuncId);
        logdebug("switch sum,time:%lu", sysTmrMsRunMs(tmptmr));

        sysTmrMsBegin(tmptmr);
        doSwitchIfSpeed(1, useFuncId);
        logdebug("if sum,time:%lu", sysTmrMsRunMs(tmptmr));

        sysTmrMsBegin(tmptmr);
        doSwitchIfSpeed(2, useFuncId);
        logdebug("map sum,time:%lu", sysTmrMsRunMs(tmptmr));
    }
    return 1;
}
